package org.csu.mypetstore.api.controller.front;


import org.csu.mypetstore.api.common.CommonResponse;
import org.csu.mypetstore.api.entity.Category;
import org.csu.mypetstore.api.entity.LongCart;
import org.csu.mypetstore.api.service.AccountService;
import org.csu.mypetstore.api.service.CatalogService;
import org.csu.mypetstore.api.service.LongCartService;
import org.csu.mypetstore.api.vo.AccountVO;
import org.csu.mypetstore.api.vo.ItemVO;
import org.csu.mypetstore.api.vo.LongCartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/longCart")
public class LongCartController {

    @Autowired
    private AccountService accountService;

    @Autowired
    private CatalogService catalogService;

    @Autowired
    private LongCartService longCartService;

    @GetMapping("{id}/longcarts")
    @ResponseBody
    public CommonResponse<LongCartVO> getLongCart(@PathVariable("id") String username){
        //return  null;
        System.out.println(longCartService.getLongCart(username));
        return longCartService.getLongCart(username);
    }

    @GetMapping("longcarts/{id}")
    @ResponseBody
    public CommonResponse<ItemVO> getProductInLongCart(@PathVariable("id") String ItemId){
        //return null;
        return longCartService.getProductInLongCart(ItemId);
    }

    @PostMapping("{username}/longcart_insert/{id}")
    @ResponseBody
    public CommonResponse<LongCartVO> insertItemtoLongCart(@PathVariable("username") String username,
                                                               @PathVariable("id") String itemId,
                                                       HttpSession session){
        return longCartService.insertItemtoLongCart(username,itemId);
    }

    @PostMapping("longcart_delete")
    @ResponseBody
    public CommonResponse<LongCartVO> deleteItemInLongCartByRequest(@RequestParam String username,
                                                               @RequestParam String itemId,
                                                               HttpSession session){
        return longCartService.deleteItemInLongCart(username,itemId);
    }

    @PostMapping("longcart_insert")
    @ResponseBody
    public CommonResponse<LongCartVO> insertItemtoLongCartByRequest(@RequestParam String username,
                                                               @RequestParam String itemId,
                                                               HttpSession session){
        return longCartService.insertItemtoLongCart(username,itemId);
    }

    @PostMapping("{username}/longcart_delete/{id}")
    @ResponseBody
    public CommonResponse<LongCartVO> deleteItemInLongCart(@PathVariable("username") String username,
                                                               @PathVariable("id") String itemId,
                                                               HttpSession session){
        return longCartService.deleteItemInLongCart(username,itemId);
    }
}
